package com.blockchain.front.servlets.financial;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.GdState;
import com.blockchain.common.enums.ZfType;
import com.blockchain.framework.http.servlet.annotation.PagingServlet;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.exception.ParameterException;
import com.blockchain.front.service.common.entity.GdEntity;
import com.blockchain.front.service.financial.FinancialManage;
import com.blockchain.front.service.financial.GdManage;
import com.blockchain.front.service.financial.entity.UserZhEntity;
import com.blockchain.util.parser.BigDecimalParser;
import com.blockchain.util.parser.EnumParser;
@PagingServlet(itemServlet = GdList.class)
public class GdList extends AbstractFinancialServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		forwardView(request, response, GdList.class);
	}

	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		String skzh=request.getParameter("skzh");
		String lxdh=request.getParameter("lxdh");
		ZfType zftype = EnumParser.parse(ZfType.class, request.getParameter("zftype"));
		FinancialManage financialmanage=serviceSession.getService(FinancialManage.class);
		GdManage manage=serviceSession.getService(GdManage.class);
		GdEntity gdEntity = new GdEntity();
		try {
			BigDecimal gdsl=BigDecimalParser.parse(request.getParameter("gdsl"));
			BigDecimal gddj=BigDecimalParser.parse(request.getParameter("gddj"));
			if (gdsl.compareTo(financialmanage.getCny().cny_ky) < 0) {
				throw new ParameterException("余额不足");
			}
			gdEntity.gdsl = gdsl;
			gdEntity.gddj = gddj;
			gdEntity.zfType = zftype;
			gdEntity.skzh = skzh;
			gdEntity.lxdh = lxdh;
		} catch (Exception e) {
			throw new ParameterException("输入信息不合法");
		}
		gdEntity.gdState = GdState.DSH;
		manage.addGdOrder(gdEntity);
		//ConfigureProvider configureProvider = ResourceRegister.getResourceProvider(getServletContext()).getResource(ConfigureProvider.class);
		sendRedirect(request,response,getController().getViewURI(request,  GdList.class));
	}
	
}
